<%@ page import="java.io.* , java.util.*, java.sql.*, com.myapp.struts.dao.* , com.myapp.struts.actionform.*, com.myapp.struts.beans.*" %>
<html>
    <head>
        <title>Trial</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <link href="../../../../css/cms.css" rel="stylesheet" type="text/css">
    </head>

    <body>
        <% String accountHead;
            String pd1;
            String pm1;
            String py1;
            String date;
            String pd2;
            String pm2;
            String py2;
            String date1;
            pd1 = request.getParameter("daydropdown");
            pm1 = request.getParameter("monthdropdown");
            py1 = request.getParameter("yeardropdown");

            pd2 = request.getParameter("daydropdown2");
            pm2 = request.getParameter("monthdropdown2");
            py2 = request.getParameter("yeardropdown2");
            accountHead = request.getParameter("achead");
            date = py1 + "-" + pm1 + "-" + pd1;
            date1 = py2 + "-" + pm2 + "-" + pd2;
            String acheadtype = "", openingBalance = "";
            AcheadDao imdao = new AcheadDao();
            ArrayList gp = imdao.acheadDetails(accountHead);
            if (gp != null) {
                Iterator itin = gp.iterator();

                while (itin.hasNext()) {
                    AccountHeadBean gb = (AccountHeadBean) itin.next();

                    /** Selected Account Head  Opening balance and entry type */
                    acheadtype = gb.getDescription();
                    openingBalance = gb.getOBalance();
                    System.out.println("openingBalance=" + openingBalance);
                }
            }
        %>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <th colspan="8" scope="col">TRIAL BALANCE</th>
            </tr>
            <tr>
                <td colspan="4" align="right"><strong>Dr</strong></td>
                <td colspan="4" align="right"><strong>Cr</strong></td>
            </tr>
            <tr>
                <th width="12%" height="24">Date</th>
                <th width="12%">Description</th>
                <th width="8%">Ref</th>
                <th width="17%">Closing Balance</th>
                <th width="13%" height="24">Date</th>
                <th width="17%">Description</th>
                <th width="7%">Ref</th>
                <th width="14%">Closing Balance</th>
            </tr>
            <tr>
                <td colspan="4" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-right: #000000 1px solid;
                                                    border-top: #000000 1px solid; border-left: #000000 1px solid;   font-size: 9pt; color: #000000; font-family: Arial;">
                        <%
                    double crtotal = 0.00, drtotal = 0.00, total = 0.00;
                        %>
                        <%
                    String voucherDate1 = "", description1 = "", reference1 = "", amount1 = "";

                    LedgerDao rvdao = new LedgerDao();
                    Vector rv = rvdao.getOpeningBalanceLedger("Dr", date, date1);
                    if (rv != null) {
                        System.out.println("Not Null rececipts");
                        Iterator itg = rv.iterator();
                        while (itg.hasNext()) {
                            LedgerBean gb = (LedgerBean) itg.next();
                            voucherDate1 = gb.getVoucherDate();
                            description1 = gb.getAccountHead();
                            reference1 = gb.getRef();
                            amount1 = gb.getClosingBalance();
                        %>
                        <tr>
                            <td width="24%" align="center"><%=voucherDate1%></td>
                            <td width="25%"><%=description1%></td>
                            <td width="16%" align="center"><%=reference1%></td>
                            <td width="35%" align="right"><%=amount1%></td>
                        </tr>
                        <%    }
            }%>
                    </table>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-right: #000000 1px solid;
                           border-bottom: #000000 1px solid; font-size: 9pt; color: #000000; font-family: Arial;">
                        <%
                  String voucherDate = "", description = "", reference = "", amount = "";

                  LedgerDao rvdao1 = new LedgerDao();
                  Vector tb = rvdao1.trialBalance("Dr", date, date1);
                  System.out.print("******" + tb);
                  if (tb != null) {
                      Iterator itg1 = tb.iterator();
                      System.out.println("***********Not Null rececipts " + itg1.hasNext());
                      while (itg1.hasNext()) {
                          LedgerBean gb1 = (LedgerBean) itg1.next();
                          voucherDate = gb1.getVoucherDate();
                          description = gb1.getDescription();
                          reference = gb1.getRef();
                          amount = gb1.getClosingBalance();
                          System.out.println("***********************description" + description);
                        %>
                        <tr>
                            <td width="24%" align="center"><%=voucherDate%></td>
                            <td width="25%"><%=description%></td>
                            <td width="16%" align="center"><%=reference%></td>
                            <td width="35%" align="right"><%=amount%></td>
                        </tr>
                        <%    }
            }%>
                    </table></td>
                <td colspan="4" valign="bottom"><table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-right: #000000 1px solid;
                                                       border-top: #000000 1px solid; border-left: #000000 1px solid;  font-size: 9pt; color: #000000; font-family: Arial;">
                        <%  LedgerDao ldao = new LedgerDao();
                    Vector cr = ldao.getOpeningBalanceLedger("Cr", date, date1);
                    if (cr != null) {
                        System.out.println("Not Null rececipts");
                        Iterator itg = cr.iterator();
                        while (itg.hasNext()) {
                            LedgerBean gb1 = (LedgerBean) itg.next();
                            voucherDate = gb1.getVoucherDate();
                            description = gb1.getDescription();
                            reference = gb1.getRef();
                            amount = gb1.getClosingBalance();
                        %>
                        <tr>
                            <td width="25%" height="18" align="center"><%=voucherDate%></td>
                            <td width="34%"><%=description%></td>
                            <td width="14%"><%=reference%></td>
                            <td width="27%" align="right"><%=amount%></td>
                        </tr>
                        <%}
                    }
                        %>
                    </table>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-right: #000000 1px solid;
                           border-bottom: #000000 1px solid; font-size: 9pt; color: #000000; font-family: Arial;">
                        <%  LedgerDao ldao2 = new LedgerDao();
                  Vector cr2 = ldao2.trialBalance("Cr", date, date1);
                  if (cr2 != null) {
                      System.out.println("Not Null rececipts");
                      Iterator itg = cr2.iterator();
                      while (itg.hasNext()) {
                          LedgerBean gb1 = (LedgerBean) itg.next();
                          voucherDate = gb1.getVoucherDate();
                          description = gb1.getDescription();
                          reference = gb1.getRef();
                          amount = gb1.getClosingBalance();
                        %>
                        <tr>
                            <td width="25%" align="center"><%=voucherDate%></td>
                            <td width="34%"><%=description%></td>
                            <td width="14%"><%=reference%></td>
                            <td width="27%" align="right"><%=amount%></td>
                        </tr>
                        <%}
                  }
                        %>
                    </table></td>
            </tr>

            <tr>
                <td height="20" colspan="4" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-right: #000000 1px solid;
                                                                border-top: #000000 1px solid; border-left: #000000 1px solid;  border-bottom: #000000 1px solid; font-size: 9pt; color: #000000; font-family: Arial;">
                        <%
                    LedgerDao ldao1 = new LedgerDao();
                    double totalDr = ldao1.getTrialBalanceTotal("Dr", date, date1);
                        %>
                        <tr>
                            <td width="24%" height="18" align="center">&nbsp;</td>
                            <td width="25%"><strong>Total Amount</strong></td>
                            <td width="16%" align="center">&nbsp;</td>
                            <td width="35%" align="right"><%=totalDr%></td>
                        </tr>
                    </table></td>
                <td height="20" colspan="4" valign="bottom"><table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-right: #000000 1px solid;
                                                                   border-top: #000000 1px solid; border-left: #000000 1px solid;  border-bottom: #000000 1px solid; font-size: 9pt; color: #000000; font-family: Arial;">
                        <%
                    LedgerDao ldao3 = new LedgerDao();
                    double totalCr = ldao3.getTrialBalanceTotal("Cr", date, date1);
                        %>
                        <tr>
                            <td width="25%" height="18" align="center">&nbsp;</td>
                            <td width="34%"><strong>Total Amount</strong></td>
                            <td width="14%">&nbsp;</td>
                            <td width="27%" align="right"><%=totalCr%></td>
                        </tr>
                    </table></td>
            </tr>
        </table>
    </body>
</html>